class Solution:
	# @return a list of lists of integer
	# dire 0, 1, 2, 3 = right, down, left, up
	def generateMatrix(self, n):
		ans = [[None for j in xrange(n)] for i in xrange(n)]
		i = j = 0
		dire_f = 0
		dire_i = [0, 1, 0, -1]
		dire_j = [1, 0, -1, 0]
		for x in xrange(n*n):
			ans[i][j] = x + 1
			temp_i = i + dire_i[dire_f]
			temp_j = j + dire_j[dire_f]
			if temp_i < n and temp_j < n and temp_i >= 0 and temp_j >= 0 and ans[temp_i][temp_j] is None:
				i, j = temp_i, temp_j
			else:
				dire_f = (dire_f + 1) % 4
				i += dire_i[dire_f]
				j += dire_j[dire_f]
		return ans

if __name__ == '__main__':
	so = Solution()
	print so.generateMatrix(4)